package cn.sf.sufingcommentprovider.serviceImpl;

import cn.sf.pojo.Comment;
import cn.sf.pojo.Reply;
import cn.sf.service.CommentService;
import cn.sf.sufingcommentprovider.dao.CommentMapper;
import cn.sf.sufingcommentprovider.dao.ReplyMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: CommentService
 * @author: 24629
 * @create: 2020-08-18 08:34
 **/
@RestController
public class CommentServiceImpl implements CommentService {

    @Resource
    private CommentMapper commentMapper;

    @Resource
    private ReplyMapper replyMapper;

    /**
     * @Author: 24629
     * @Time: 2020/8/18 16:18
     * @Description: 根据商品id查询底下评论，评论用户信息，及评论回复
     * @Param: [videoId]    视频id
     * @Return: java.util.List<cn.sf.pojo.Comment>
     */
    @Override
    @RequestMapping("/queryCommentAndReply")
    public List<Comment> queryCommentAndReply(long videoId) {
        return commentMapper.queryCommentAndReply(videoId);
    }

    @Override
    @RequestMapping("/addComment")
    public boolean addComment(long userId, long videoId, String message, String picture) {
        if(commentMapper.addComment(userId, videoId, message, picture)>0){
            return true;
        }
        return false;
    }

    @Override
    @RequestMapping("/addReply")
    public boolean addReply(@RequestBody Reply reply) {
        if(replyMapper.addReply(reply)){
            return true;
        }
        return false;
    }

    @Override
    @RequestMapping("/queryCommentCount")
    public int queryCommentCount(long videoId) {
        return commentMapper.queryCommentCount(videoId);
    }
}
